package com.ruoyi.web.controller.fx;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.fx.FxNotice;
import com.ruoyi.system.service.fx.IFxNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 公告Controller
 *
 * @author ruoyi
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/fx/notice")
public class FxNoticeController extends BaseController {
    @Autowired
    private IFxNoticeService fxNoticeService;

    /**
     * 查询公告列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FxNotice fxNotice) {
        startPage();
        List<FxNotice> list = fxNoticeService.selectFxNoticeList(fxNotice);
        return getDataTable(list);
    }

    /**
     * 公告内容循环
     * @return
     */
    @GetMapping("/strList")
    public AjaxResult strList() {
        return success(fxNoticeService.selectNoticeStr());
    }

    /**
     * 导出公告列表
     */
    @Log(title = "公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FxNotice fxNotice) {
        List<FxNotice> list = fxNoticeService.selectFxNoticeList(fxNotice);
        ExcelUtil<FxNotice> util = new ExcelUtil<FxNotice>(FxNotice.class);
        util.exportExcel(response, list, "公告数据");
    }

    /**
     * 获取公告详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fxNoticeService.selectFxNoticeById(id));
    }

    /**
     * 新增公告
     */
    @Log(title = "公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FxNotice fxNotice) {
        return toAjax(fxNoticeService.insertFxNotice(fxNotice));
    }

    /**
     * 修改公告
     */
    @Log(title = "公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FxNotice fxNotice) {
        return toAjax(fxNoticeService.updateFxNotice(fxNotice));
    }

    /**
     * 删除公告
     */
    @Log(title = "公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fxNoticeService.deleteFxNoticeByIds(ids));
    }
}
